home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / incl / LEDA.020+881 / _Point.h next >
C/C++ Source or Header  |  1994-11-02  |  3KB  |  134 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  Point.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_POINTEXACT_H
  16. #define LEDA_POINTEXACT_H
  17.  
  18. #include <LEDA/Int.h>
  19.  
  20. class Point;
  21. class Segment;
  22.  
  23.  
  24. //------------------------------------------------------------------------------
  25. // Points
  26. //------------------------------------------------------------------------------
  27.  
  28. class Point_rep  : public handle_rep {
  29.  
  30. friend class Point;
  31. friend class Segment;
  32.    
  33.    Int x;
  34.    Int y;
  35.    Int w;
  36.  
  37. public:
  38.     
  39.    Point_rep();     
  40.    Point_rep(Int a, Int b);
  41.    Point_rep(Int a, Int b, Int c);
  42.  
  43.   ~Point_rep() {}
  44.    
  45.    
  46.    LEDA_MEMORY(Point_rep)
  47.    
  48. };
  49.  
  50.  
  51. class Point  : public handle_base 
  52. {
  53.  
  54. friend class Segment;
  55. friend class Line;
  56. friend class Circle;
  57.  
  58.  
  59. Point_rep* ptr() const { return (Point_rep*)PTR; }   //does type casting
  60.  
  61. public:
  62.  
  63.  Point();
  64.  Point(Int, Int);
  65.  Point(Int, Int, Int);
  66. // Point(vector);
  67.  Point(const Point& p) : handle_base(p) {}  //increase reference counter by one
  68. ~Point()                  { clear(); }
  69.  
  70. Point& operator=(const Point& p) { handle_base::operator=(p); return *this; }
  71.  
  72.  
  73. //operator vector()         { return vector(ptr()->x,ptr()->y); }
  74.  
  75. double xcoord() const { return Itodouble(ptr()->x)/Itodouble(ptr()->w);}
  76. double ycoord() const { return Itodouble(ptr()->y)/Itodouble(ptr()->w);}
  77.  
  78. #if defined(__GNUG__)
  79. Int X() const { return ptr()->x; }
  80. Int Y() const { return ptr()->y; }
  81. Int W() const { return ptr()->w; }
  82. #else
  83. const Int& X() const { return ptr()->x; }
  84. const Int& Y() const { return ptr()->y; }
  85. const Int& W() const { return ptr()->w; }
  86. #endif
  87.  
  88. double XD() const { return Itodouble(ptr()->x); }
  89. double YD() const { return Itodouble(ptr()->y); }
  90. double WD() const { return Itodouble(ptr()->w); }
  91.  
  92. //double  angle(const Point&, const Point&) const;
  93.  
  94. //double  distance(const Point&) const;
  95. //double  distance() const;
  96.  
  97. //Point   translate(double,double) const;
  98. //Point   translate(const vector&) const;
  99.  
  100. //Point   rotate(const Point&,double) const;
  101. //Point   rotate(double) const;
  102.  
  103.  
  104. //Point operator+(const vector& v) const { return translate(v); }
  105.  
  106. int operator==(const Point&) const;
  107.  
  108. int operator!=(const Point& p)  const { return !operator==(p);}
  109.  
  110. friend ostream& operator<<(ostream& out, const Point& p) ;
  111. friend istream& operator>>(istream& in, Point& p) ;
  112.  
  113. friend void Print(const Point&, ostream& = cout);
  114. friend void Read(Point&,  istream& = cin);
  115.  
  116. /*
  117. friend int compare(const Point& a, const Point& b)
  118. { Int d = a.X() * b.W() - b.X() * a.W();
  119.   if (sign(d) == 0) d = a.Y() * b.W()- b.Y() * a.W();
  120.   return sign(d);
  121. }
  122. */
  123.  
  124. };
  125.  
  126. inline void Print(const Point& p, ostream& out) { out << p; } 
  127. inline void Read(Point& p,  istream& in)        { in >> p; }
  128.  
  129. LEDA_HANDLE_TYPE(Point)
  130.  
  131. #endif
  132.  
  133.